package es

import (
	"fmt"
	"github.com/elastic/elastic-transport-go/v8/elastictransport"
	"github.com/elastic/go-elasticsearch/v8"
	"os"
)

var TypeClient *elasticsearch.TypedClient

const (
	LunWenIndex = "lun_wen_index"
	VideoIndex  = "video_index"
)

// https://www.elastic.co/guide/en/elasticsearch/reference/8.15/docker.html#docker-cli-run-dev-mode
func init() {
	// todo 地址改为读配置文件
	client, err := elasticsearch.NewTypedClient(elasticsearch.Config{
		Logger: &elastictransport.JSONLogger{
			Output:             os.Stdout,
			EnableRequestBody:  true,
			EnableResponseBody: true,
		},
		Addresses: []string{"https://localhost:9200"},
		Username:  "elastic",
		Password:  "s-VqkNxZXJKudYyUWwun",
		CACert: []byte(`-----BEGIN CERTIFICATE-----
MIIFWTCCA0GgAwIBAgIUCzUwzYVwPJ52s+03HvLkCZfjbGEwDQYJKoZIhvcNAQEL
BQAwPDE6MDgGA1UEAxMxRWxhc3RpY3NlYXJjaCBzZWN1cml0eSBhdXRvLWNvbmZp
Z3VyYXRpb24gSFRUUCBDQTAeFw0yNDA4MDkwMjA2MzRaFw0yNzA4MDkwMjA2MzRa
MDwxOjA4BgNVBAMTMUVsYXN0aWNzZWFyY2ggc2VjdXJpdHkgYXV0by1jb25maWd1
cmF0aW9uIEhUVFAgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCi
T64eqFMvS2tClUV3NWoDVKriAjF+8aXJgzosDccSjp77D/6onAVo3rmIc7u7KNDv
aENYWZsWmCauqs1JSy/QsYh4nKTUjsgL6DZAdJ1rNWQ/xhssD9ysSGu5etcImXgX
/CWQtIgQFErOwr6yfOJxogFLUZk7xg88RE5Pt6bl9BH8gQICwgynE3JrF8KSGB7C
pEZc7UTX6LNe+ZtoqvMsmN0GLLrpDMxl980yQs49UIdYvOL2JSXsqfbl5DMmoDd5
MacI8giGn9D9Mg6NEYEAo2jxFUuSWqIJLSuw8qBCFRA1YhHW2GPGTK1bCRb+T11z
cViLCUDkhJbJr4C0fSKD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